package com.isoftstone.demo.common.exception;

import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//@Controller
public class CustomExceptionResolver implements HandlerExceptionResolver {
	
	@Override
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {
		ProductException pex = null;
		if(ex instanceof ProductException){
			pex = (ProductException)ex;
		}else {
		    pex = new ProductException("系统错误");
		}
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("message", pex.getMessage());
		modelAndView.setViewName("undev");
		return modelAndView;
	}
}
